# gozerbot/less.py
#
#

__copyright__ = 'this file is in the public domain'

from gozerbot.persist import Persist
from gozerbot.limlist import Limlist
from gozerbot.datadir import datadir

class Less(Persist):

    def __init__(self, fname):
        Persist.__init__(self, fname)
        if not self.data:
            self.data = {}

    def add(self, nick, listoftxt):
        nick = nick.lower()
        if not self.data.has_key(nick):
            self.data[nick] = Limlist(5)
        self.data[nick].insert(0, listoftxt)

    def get(self, nick, index1, index2):
        nick = nick.lower()
        try:
            txt = self.data[nick][index1][index2]
        except (KeyError, IndexError):
            txt = None
        return txt

    def size(self, nick):
        nick = nick.lower()
        sizes = []
        if not self.data.has_key(nick):
            return sizes
        for i in self.data[nick]:
            sizes.append(len(i))
        return sizes

less = Less(datadir + '/less')
